package com.zhong.bmob.server;

import com.zhong.bmob.inter.IFindUserDown;
import com.zhong.bmob.model.User;

import java.util.List;

import cn.bmob.v3.BmobQuery;
import cn.bmob.v3.exception.BmobException;
import cn.bmob.v3.listener.FindListener;

/**
 * Created by 俊峰 on 2017/5/19.
 * 用于查找用户，根据用户名
 */

public class FindUser {
    public static void query(String userName, IFindUserDown findUserDown){
        final IFindUserDown iFindUserDown = findUserDown;
        BmobQuery<User> query = new BmobQuery<>();
        query.addWhereEqualTo("username", userName);
        query.findObjects(new FindListener<User>() {
            @Override
            public void done(List<User> list, BmobException e) {
                if (e == null){
                    iFindUserDown.findSuccess(list.get(0));
                }else {
                    iFindUserDown.findFail(e);
                }
            }
        });
    }
}
